package com.king.hrmsdev.controller;

import com.alibaba.fastjson.JSONObject;
import com.king.hrmsdev.entity.Role;
import com.king.hrmsdev.pojo.Vuserinfo;
import com.king.hrmsdev.service.RoleService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Auther:SnakeKing
 * @Date: 2019-09-22
 * @Description: com.king.hrmsdev.controller
 * @version:1.0
 */
@RestController
public class RoleController {
    @Resource
    private RoleService roleService;

    @RequestMapping(value = "/Findallrole", method = RequestMethod.POST)
    public JSONObject roleList() {
        List<Role> allrolelist = roleService.FindAllRole();
        JSONObject result = new JSONObject();
        result.put("msg", "ok");
        result.put("method", "roleList");
        result.put("allrolelist", allrolelist);
        return result;
    }

    @RequestMapping(value = "/Insertrole", method = RequestMethod.POST)
    public int InsertRole(@RequestParam(value = "role") String role) {
        int flag = roleService.InsertRole(role);
        return flag;
    }


    @RequestMapping(value = "/Updaterole", method = RequestMethod.POST)
    public int Updaterole(@RequestParam("role_id") Integer role_id,
                          @RequestParam("role") String role) {

        int flag = roleService.UpdateRole(role_id, role);
        return flag;
    }


    @RequestMapping(value = "/deleterole", method = RequestMethod.POST)
    public int deleterole(@RequestParam("role_id") int role_id) {
        int flag = roleService.DeleteRole(role_id);
        return flag;
    }



    @RequestMapping(value = "/FindAllUser", method = RequestMethod.POST)
    public JSONObject FindAllUser() {
        List<Vuserinfo> alluserlist = roleService.FindAllUser();
        JSONObject result = new JSONObject();
        result.put("msg", "ok");
        result.put("method", "FindAllUser");
        result.put("alluserlist", alluserlist);
        return result;
    }

    @RequestMapping(value = "/Updateuser", method = RequestMethod.POST)
    public int Updateuser(@RequestParam("user_id") int user_id,
                          @RequestParam("username") String username,
                          @RequestParam("password") String password,
                          @RequestParam("wechat") String wechat,
                          @RequestParam("role_id") int role_id,
                          @RequestParam("state") int state) {

        Vuserinfo vuserinfo = new Vuserinfo();
        vuserinfo.setUser_id(user_id);
        vuserinfo.setUsername(username);
        vuserinfo.setPassword(password);
        vuserinfo.setWechat(wechat);
        vuserinfo.setRole_id(role_id);
        vuserinfo.setState(state);
        int flag = roleService.Updateuser(vuserinfo);
        return flag;
    }

    @RequestMapping(value = "/Insertuser", method = RequestMethod.POST)
    public int Insertuser(@RequestParam("job_id") int job_id,
                          @RequestParam("username") String username,
                          @RequestParam("password") String password,
                          @RequestParam("wechat") String wechat,
                          @RequestParam("role_id") int role_id) {

        Vuserinfo vuserinfo = new Vuserinfo();
        vuserinfo.setJob_id(job_id);
        vuserinfo.setUsername(username);
        vuserinfo.setPassword(password);
        vuserinfo.setWechat(wechat);
        vuserinfo.setRole_id(role_id);
        vuserinfo.setState(1);
        int flag = roleService.Insertuser(vuserinfo);
        return flag;
    }



}
